package com.example.demo.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.groups.Default;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.LocalTime;

@NoArgsConstructor// 生成无参的构造方法
@AllArgsConstructor// 生成满参的构造方法
@Accessors(chain = true)// 使用链式调用
@Data// 自动生成get/set方法、重写toString方法等方法
public class User implements Serializable {

    // 主键
    @NotNull(groups = Update.class)//分组校验，update时校验
    @ApiModelProperty(value = "主键")
    private String id;

    // 用户名
    @NotEmpty(groups = {Add.class, Update.class})//分组校验，add和update时校验
    @Pattern(regexp = "^\\S{5,16}$")
    @ApiModelProperty(value = "用户名")
    private String name;

    // 密码
    @JsonIgnore//转json时不加入
    @ApiModelProperty(value = "密码")
    private String password;

    @Email
    @ApiModelProperty(value = "邮箱")
    private String email;

    @JsonFormat(pattern = "yyyy-MM-dd HH::mm:ss")
    private LocalDateTime updateTime;

    //没指定分组，默认Default
    //分组间可继承
    public interface Add extends Default {

    }

    public interface Update extends Default {

    }
}